package com.study.controller;

import com.bus.entity.Goods;
import com.bus.entity.Provider;
import com.bus.service.GoodsService;
import com.bus.service.ProviderService;
import com.study.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/pur")
public class PurController {
    @Autowired
    ProviderService providerService;

    @Autowired
    GoodsService goodsService;

    @RequestMapping(value = "/purAdd",method = RequestMethod.GET)
    public ModelAndView addUser() {
        ModelAndView mv = new ModelAndView();
        // 获取角色信息
        List<Provider> list = providerService.selectAll();
        mv.addObject("list",list);
        mv.setViewName("pur-add");
        return mv;
    }

    @RequestMapping(value = "/bySell")
    @ResponseBody
    public List<Goods> bySell(HttpServletRequest request){
        return goodsService.selectAllById(request.getParameter("providerName"));
    }

    @RequestMapping(value = "/purPrice")
    @ResponseBody
    public List<Goods> purPrice(HttpServletRequest request){
        return goodsService.selectPrice(request.getParameter("goodsName"));
    }

    @RequestMapping(value = "/addTwo")
    @ResponseBody
    public void tableAddTwo(HttpServletRequest request){

    }
}
